import { Application } from "kilom/lib/Application";
import { gameIdDic, SvrType } from "../../config/SvrCfg";
import { ServerMain } from "../ServerMain";

/**
 * Connector服务器
 */
export const connectorMain = _ as ConnectorMain;
export class ConnectorMain extends ServerMain {

    init() {
        (connectorMain as any) = this;

        //路由到sid对应的game服务器
        this.app.setSvrRouter(SvrType.game, (sess) => {
            let gameId = gameIdDic[sess.getLocal("sid")];
            return this.app.svrCfgIdMap[gameId];
        });

        this.app.miscCfg.onClientClose = sess => {
            if (sess.uid) {
                let gameSvr = this.app.getSvrWidthRouter(SvrType.game, sess);
                gameSvr && this.app.rpc(gameSvr.id).game.main.delPlayer(sess.uid);
            }
        }
    }

}